package com.leetcode.partition17;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/1/9 15:39
 */
public class LC1629按键持续时间最长的键 {

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] s = reader.readLine().split("\\s+");
        int[] releaseTimes = new int[s.length];
        for (int i = 0; i < s.length; i++) releaseTimes[i] = Integer.parseInt(s[i]);
        String keysPressed = reader.readLine();
        writer.write(slowestKey(releaseTimes, keysPressed));
        writer.flush();
    }

    public static char slowestKey(int[] releaseTimes, String keysPressed) {
        int answer = 0, duringTime = releaseTimes[0];
        for (int i = 1; i < releaseTimes.length; i++) {
            int during = releaseTimes[i] - releaseTimes[i - 1];
            if (during >= duringTime) {
                if (during == duringTime && keysPressed.charAt(answer) > keysPressed.charAt(i)) {
                    continue;
                }
                answer = i;
                duringTime = during;
            }
        }
        return keysPressed.charAt(answer);
    }
}
